﻿<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>角色列表</title>
    
    <link rel="shortcut icon" href="favicon.ico">
	<link href="css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="css/font-awesome.min.css?v=4.4.0" rel="stylesheet">

    <!-- Data Tables -->
    <link href="css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="js/plugins/layui/css/layui.css" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="css/style.min.css?v=4.0.0" rel="stylesheet" />

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">

<!-- 页面提示 -->
<div class="collapse" id="collapseExample" style="position:absolute;left:30%;">
	<div class="alert alert-warning alert-dismissable" style="padding:8px;margin-bottom:0px;" >
		<button aria-hidden="true" data-dismiss="alert" style="right:0;" class="close" type="button">×</button>
		只有超级管理员（开发人员）才能新增、删除、禁用角色！
	</div>
</div>
                    <div class="ibox-title" style="height:72px;">
                        <div class="ibox-tools">
							<a class="collapse-link" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
								<i class="fa fa-warning"></i>
							</a>
                            <a class="collapse-link" href="javascript:location.href=location.href;">
                                <i class="fa fa-refresh"></i>
                            </a>
                        </div>
                        <h5>基本 <small>分类/查找</small></h5>
						<div class="col-sm-12">
						<div class="col-sm-6">
							<div class="col-sm-5">
							<div class="input-group input-group-sm ">
								<input name="roleCodeOrName" type="text" class="form-control" placeholder="角色名称或代码"> 
								<span class="input-group-btn"> 
								<button type="button" id="searchSysRole" class="btn btn-primary">搜索
								</button> </span>
							</div>
							</div>
						</div>
						<div class="col-sm-6 text-right">
							<button id="showAddSysRole" type="button" class="btn btn-sm btn-success add">新增</button>
						</div>
						</div>
                    </div>
                    <div class="ibox-content">

                        <table id="layTab" class="table table-striped table-bordered table-hover dataTables-example">
                            <thead>
                                <tr>
                                    <th>角色名称</th>
                                    <th>角色代码</th>
                                    <th>状态</th>
                                    <th>创建人</th>
                                    <th>创建时间</th>
                                    <th>更新人</th>
                                    <th>更新时间</th>
									<th>备注</th>
									<th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
							<tfoot>
							
							</tfoot>
                        </table>

                    </div>
                </div>
            </div>
        </div>
        
    </div>
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.5"></script>
	<script src="js/plugins/toastr/toastr.min.js"></script>
	<script src="js/plugins/layui/layui.js"></script>
	<script src="js/custom/layTool.js"></script>
    <script type="text/javascript" src="js/custom/app.js" charset="UTF-8"></script>
    <script type="text/javascript" src="js/custom/tools.js" charset="UTF-8"></script>
    <script>
	var pageSize = 10;
	var pageNumber = 1;
	function searchSysRole(pageNumber ,pageSize,roleCodeOrName){
		var url = 'sysRole/querySysRoleByPage';
		jQuery.ajax({
			url:domain + url,
			type:"get",
			data:{"page":pageNumber,"pageSize":pageSize,"roleCodeOrName":roleCodeOrName},
			crossDomain:true,
			xhrFields:{
				withCredentials:true
			},
			success:function (data) {
				if(data.status == 200){
					var totalPage = data.data.total;//总页数
					pageNumber = data.data.page;//当前页
					var totalRow = data.data.records;//总条数
	   
					//拼凑html
					combHTML(data.data.rows);
					var arr = [roleCodeOrName];
				   //分页
					LayPage('layTab',totalPage,totalRow,pageNumber ,pageSize,"searchSysRole",arr);
				}else{
					top.toastr.warning(data.msg);
				}
			},
			error:function(data) {
				top.toastr.error("查询列表失败，请检查网络");
			}
		})
		
	}
	
	function combHTML(data){
		var htmls = new Array();
		for (var i=0;i<data.length;i++){
			htmls.push('<tr class="gradeU">');
			htmls.push('		<td>'+ data[i].roleName +'</td>');
			htmls.push('		<td>'+ data[i].roleCode +'</td>');
			htmls.push('		<td>'+ getStatus(data[i].status) +'</td>');
			htmls.push('		<td>'+ data[i].createBy +'</td>');
			htmls.push('		<td class="center">'+ data[i].createTime +'</td>');
			htmls.push('		<td>'+ data[i].updateBy +'</td>');
			htmls.push('		<td>'+ data[i].updateTime +'</td>');
			htmls.push('		<td>'+ data[i].note +'</td>');
			htmls.push('		<td><button type="button" data-code="'+ data[i].roleCode 
									+'" class="btn btn-xs btn-outline btn-warning showUpdateRole update">修改</button>');
			htmls.push('		<button type="button" data-code="'+ data[i].roleCode 
									+'" class="btn btn-xs btn-outline btn-danger showDeleteRole delete">删除</button></td>');
			htmls.push('</tr>');
							
		}
		$("#layTab tbody").html(htmls.join(''));
		
		
		//修改角色
		$(".showUpdateRole").on("click",function(){
			var roleCode = $(this).data("code");
			layerOpen('修改角色','role-edit.html?roleCode='+encodeURI(roleCode),'600','300')
		});
		
		//删除角色
		$(".showDeleteRole").on("click",function(){
			var roleCode = $(this).data("code");
			deleteSysRole(roleCode);
		});
		
	}
	
	//删除角色
	function deleteSysRole(roleCode){
		layui.use(['layer'], function(){
			var layer = layui.layer;
			layer.confirm('确定删除？', {
				title:false,
				icon:7,
				btn: ["确定",'取消'] //按钮
			}, function(){
				var url = 'sysRole/deleteSysRoleByCode';
				jQuery.ajax({
					url:domain + url,
					type:"post",
					data:{"roleCode":roleCode},
					crossDomain:true,
					xhrFields:{
						withCredentials:true
					},
					success:function (data) {
						if(data.status == 200){
							top.toastr.success("操作成功");
							searchSysRole(pageNumber,pageSize,"");
							layer.close(layer.index);
						}else{
							top.toastr.warning(data.msg);
						}
					},
					error:function(data) {
						top.toastr.error("查询列表失败，请检查网络");
					}
				})
			});
		});
	}
	
	$(function(){
		searchSysRole(pageNumber,pageSize,"");
		$("#searchSysRole").on("click",function(){
			searchSysRole(pageNumber,pageSize,$("input[name=roleCodeOrName]").val());
		})
		document.onkeydown = function(event){
			event=document.all?window.event:event;
			 if((event.keyCode || event.which)==13){
				searchSysRole(pageNumber,pageSize,$("input[name=roleCodeOrName]").val());
			}
		}
		
		$("#showAddSysRole").on("click",function(){
			layerOpen('新增角色','role-add.html','600','300');
		})
	})
	
	</script>

	<script>	//=======   页面权限显示   ======//
	//当前菜单代码 (每个页面不一样，需要配置)
		var s_menuCode = "roleRun";
	//所有可用权限
		var roleAuth = app.permission(s_menuCode);
	//当前菜单所有可用权限（排除被禁用的按钮）
		var menuAuth = app.menuButtonByOn(s_menuCode);
		
		drawBtn(roleAuth,menuAuth);
	</script>
</body>

</html>
